home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume14 / jove4.9 / part14 < prev    next >
Encoding:
Internet Message Format  |  1988-04-26  |  30.9 KB

  1. Subject:  v14i070:  Jove, an emacs variant, version 4.9, Part14/21
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Jonathan Payne <jpayne@cs.rochester.edu>
  7. Posting-number: Volume 14, Issue 70
  8. Archive-name: jove4.9/part14
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 14 (of 21)."
  17. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  18. if test -f './screen.c' -a "${1}" != "-c" ; then 
  19.   echo shar: Will not clobber existing file \"'./screen.c'\"
  20. else
  21. echo shar: Extracting \"'./screen.c'\" \(28777 characters\)
  22. sed "s/^X//" >'./screen.c' <<'END_OF_FILE'
  23. X/***************************************************************************
  24. X * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  25. X * is provided to you without charge, and with no warranty.  You may give  *
  26. X * away copies of JOVE, including sources, provided that this notice is    *
  27. X * included in all the files.                                              *
  28. X ***************************************************************************/
  29. X
  30. X#include "jove.h"
  31. X#include "io.h"
  32. X#include "ctype.h"
  33. X#include "termcap.h"
  34. X
  35. X#ifdef IBMPC
  36. X
  37. X/* here come the actual emulation routines    */
  38. X
  39. X#include <dos.h>
  40. X#include <conio.h>
  41. X
  42. X#define BYTE    unsigned char
  43. X#define WORD    unsigned int
  44. X
  45. X#ifdef MAC
  46. X#    undef private
  47. X#    define private
  48. X#endif
  49. X
  50. X#ifdef    LINT_ARGS
  51. private BYTE near get_mode(void);
  52. X
  53. private WORD
  54. X    near cur_page(void),
  55. X    near get_cur(void);
  56. X
  57. private void
  58. X    near ch_out(BYTE, BYTE),
  59. X    near clr_eop(void),
  60. X    near cur_advance(void),
  61. X    near cur_down(void),
  62. X    near cur_left(void),
  63. X    near cur_right(void),
  64. X    near cur_up(void),
  65. X    near line_feed(void),
  66. X    near normfun(char),
  67. X    near scr_win(int, BYTE, BYTE, BYTE, BYTE),
  68. X    near set_cur(WORD),
  69. X    near set_mode(BYTE),
  70. X    near wherexy(BYTE *, BYTE *);
  71. X#else
  72. private BYTE near get_mode();
  73. X
  74. private WORD
  75. X    near cur_page(),
  76. X    near get_cur();
  77. X
  78. private void
  79. X    near ch_out(),
  80. X    near clr_eop(),
  81. X    near cur_advance(),
  82. X    near cur_down(),
  83. X    near cur_left(),
  84. X    near cur_right(),
  85. X    near cur_up(),
  86. X    near line_feed(),
  87. X    near normfun(),
  88. X    near scr_win(),
  89. X    near set_cur(),
  90. X    near set_mode(),
  91. X    near wherexy();
  92. X#endif    /* LINT_ARGS */
  93. X
  94. X#ifdef MAC
  95. X#    undef private
  96. X#    define private static
  97. X#endif
  98. X
  99. X#define VIDEO   0x10
  100. X
  101. X#define intr(n, r)    int86(n, r, r);
  102. X
  103. BYTE CHPL=80, 
  104. X     LPP=25, 
  105. X     CUR_PAGE=0, 
  106. X     C_ATTR = 0x07,
  107. X     C_X=0, 
  108. X     C_Y=0;
  109. X
  110. int Fgcolor = 7,
  111. X    Bgcolor = 0,
  112. X    Mdcolor = 0;
  113. X    
  114. void setcolor(fg, bg)
  115. BYTE fg, bg;
  116. X{
  117. X   C_ATTR = ((bg&0xf)<<4)|(fg&0xf);
  118. X}   
  119. X
  120. private
  121. WORD near cur_page()
  122. X{
  123. X   union REGS vr;
  124. X
  125. X   vr.h.ah = 0x0f;
  126. X   intr(VIDEO, &vr);
  127. X   return(vr.h.bh);
  128. X}
  129. X   
  130. private
  131. void near set_cur(xy)
  132. WORD xy;
  133. X{
  134. X   union REGS vr;
  135. X   
  136. X   vr.h.bh = CUR_PAGE;
  137. X   vr.h.ah = 0x02;
  138. X   vr.x.dx = xy;
  139. X   intr(VIDEO, &vr);
  140. X}
  141. X
  142. private
  143. WORD near get_cur()
  144. X{
  145. X   union REGS vr;
  146. X
  147. X   vr.h.bh = CUR_PAGE;
  148. X   vr.h.ah = 0x03;
  149. X   intr(VIDEO, &vr);
  150. X   return (vr.x.dx);
  151. X}            
  152. private
  153. BYTE near get_mode()
  154. X{
  155. X  union REGS vr;
  156. X
  157. X  vr.h.ah = 0x0f;
  158. X  intr(VIDEO, &vr);
  159. X  return(vr.h.al);
  160. X}
  161. X
  162. BYTE lpp()
  163. X{
  164. X   int far *regen = (int far *) 0x44C;
  165. X   int what;
  166. X   BYTE chpl();
  167. X   
  168. X   what = (*regen&0xff00)/2/chpl();
  169. X   return (what > 43 ? 25 : what);
  170. X}    
  171. X      
  172. private
  173. void near set_mode(n)
  174. BYTE n;
  175. X{
  176. X  union REGS vr;
  177. X
  178. X  vr.h.ah = 0x00;
  179. X  vr.h.al = n;
  180. X  intr(VIDEO, &vr);
  181. X} 
  182. X
  183. X#define gotoxy(x,y)    set_cur((x)<<8|((y)&0xff))
  184. X#define cur_mov(x,y)    set_cur((C_X=x)<<8|((C_Y=y)&0xff))
  185. X
  186. private
  187. void near wherexy( x, y)
  188. BYTE *x, *y;
  189. X{
  190. X  register WORD xy;
  191. X
  192. X  xy = get_cur();
  193. X  *x = xy>>8;
  194. X  *y = xy&0xff;
  195. X}
  196. X    
  197. X#define wherex()    C_X
  198. X#define wherey()    C_Y
  199. X
  200. private
  201. void near scr_win(no, ulr, ulc, lrr, lrc)
  202. int no;
  203. BYTE ulr, ulc, lrr, lrc;
  204. X{
  205. X  union REGS vr;
  206. X
  207. X  if (no >= 0)
  208. X     vr.h.ah = 0x06;
  209. X  else {
  210. X     vr.h.ah = 0x07;
  211. X     no = - no;
  212. X  }
  213. X  vr.h.al = no;
  214. X  vr.x.cx = ulr<<8 | ulc;
  215. X  vr.x.dx = lrr<<8 | lrc;
  216. X  vr.h.bh = C_ATTR;
  217. X  intr(VIDEO, &vr);
  218. X}    
  219. X
  220. BYTE chpl()
  221. X{
  222. X  union REGS vr;
  223. X
  224. X  vr.h.ah = 0x0f;
  225. X  intr(VIDEO, &vr);
  226. X  return(vr.h.ah);
  227. X}
  228. X   
  229. X#define clr_page()    scr_win(0, 0, 0, LPP-1, CHPL-1), \
  230. X            gotoxy(C_X = 0, C_Y = 0)
  231. X        
  232. private
  233. void near cur_right()
  234. X{
  235. X   if (C_Y < CHPL-1) 
  236. X      C_Y++;
  237. X   gotoxy(C_X, C_Y);
  238. X}         
  239. X
  240. private
  241. void near cur_up()
  242. X{
  243. X   if (C_X)
  244. X      C_X--;
  245. X   gotoxy(C_X, C_Y);
  246. X}
  247. X
  248. private
  249. void near cur_left()
  250. X{
  251. X   if (C_Y)
  252. X      C_Y--;
  253. X   gotoxy(C_X, C_Y);
  254. X}
  255. X
  256. private
  257. void near cur_down()
  258. X{
  259. X   if (C_X < LPP-1)
  260. X      C_X++;
  261. X   gotoxy(C_X, C_Y);
  262. X}
  263. X               
  264. private
  265. void near ch_out(c, n)
  266. BYTE c, n;
  267. X{
  268. X  union REGS vr;
  269. X
  270. X  vr.h.ah = 0x09;
  271. X  vr.h.al = c;
  272. X  vr.h.bl = C_ATTR;
  273. X  vr.h.bh = CUR_PAGE;
  274. X  vr.x.cx = n;
  275. X  intr(VIDEO, &vr);
  276. X}
  277. X
  278. X#define wrch(c)        ch_out((c), 1), cur_advance()
  279. X
  280. X#define home_cur()    gotoxy(C_X = 0, C_Y = 0)
  281. X
  282. X#define clr_eoln()    ch_out(' ', CHPL-wherey())
  283. X
  284. private
  285. void near clr_eop()
  286. X{
  287. X  clr_eoln();
  288. X  scr_win(LPP-1-wherex(), wherex()+1, 0, LPP-1, CHPL-1);
  289. X}
  290. X
  291. void init_43()
  292. X{
  293. X   BYTE far *info = (BYTE far *) 0x487;
  294. X   WORD far *CRTC = (WORD far *) 0x463;
  295. X   union REGS vr;
  296. X   WORD cur;
  297. X         
  298. X   CUR_PAGE = cur_page();
  299. X   CHPL = chpl();
  300. X   LPP = lpp();
  301. X
  302. X   if (get_mode()!=3)
  303. X      set_mode(3);
  304. X   cur = get_cur();
  305. X   
  306. X   vr.x.ax = 0x1112;
  307. X   vr.h.bl = 0;
  308. X   intr(VIDEO, &vr);
  309. X
  310. X   *info |= 1;
  311. X   vr.x.ax = 0x0100;
  312. X   vr.h.bh = 0;
  313. X   vr.x.cx = 0x0600;
  314. X   intr(VIDEO, &vr);
  315. X
  316. X   outp(*CRTC, 0x14);
  317. X   outp(*CRTC+1, 0x07);
  318. X
  319. X   vr.x.ax = 0x1200;
  320. X   vr.h.bl = 0x20;
  321. X   intr(VIDEO, &vr);
  322. X   
  323. X   LPP = lpp();
  324. X
  325. X   set_cur(cur);
  326. X   wherexy(&C_X, &C_Y);
  327. X}
  328. X
  329. void reset_43()
  330. X{
  331. X   BYTE far *info = (BYTE far *) 0x487;
  332. X   WORD far *CRTC = (WORD far *) 0x463;
  333. X   union REGS vr;
  334. X   
  335. X   set_mode(3);
  336. X
  337. X   *info &= 128;
  338. X   vr.x.ax = 0x0100;
  339. X   vr.h.bh = 0x0607;
  340. X   vr.x.cx = 0x0607;
  341. X   intr(VIDEO, &vr);             
  342. X
  343. X   outp(*CRTC, 0x14);
  344. X   outp(*CRTC+1, 13);
  345. X
  346. X}
  347. X
  348. X#define scr_up()        scr_win(1, 0, 0, LPP-1, CHPL-1)
  349. X#define back_space()    cur_left()
  350. X
  351. private
  352. void near line_feed()
  353. X{
  354. X   if (++C_X > LPP-1) {
  355. X      C_X = LPP-1;
  356. X      scr_up();
  357. X   }   
  358. X   gotoxy(C_X, C_Y);
  359. X}
  360. X
  361. X#define BELL_P 0x61            /* speaker */
  362. X#define BELL_D 0x2dc            /* 550 hz  */
  363. X#define TIME_P 0x40            /* timer   */
  364. X#define TINI   182            /* 10110110b timer initialization */
  365. X
  366. void dobell(x)
  367. X{
  368. X   unsigned int n = 0x8888;
  369. X   int orgval;
  370. X
  371. X   outp(TIME_P+3, TINI);
  372. X   outp(TIME_P+2, BELL_D&0xff);
  373. X   outp(TIME_P+2, BELL_D>>8);
  374. X   orgval = inp(BELL_P);
  375. X   outp(BELL_P, orgval|3);        /* turn speaker on  */
  376. X   while (--n > 0)
  377. X     ;
  378. X   outp(BELL_P, orgval);
  379. X}
  380. X
  381. X#define carriage_return()    gotoxy(wherex(), C_Y = 0)
  382. X   
  383. private
  384. void near cur_advance()
  385. X{
  386. X   if (++C_Y > CHPL-1) {
  387. X      C_Y = 0;
  388. X      if (++C_X > LPP-1) {
  389. X         scr_up();       
  390. X         C_X = LPP-1;
  391. X      }   
  392. X   }
  393. X   gotoxy(C_X, C_Y);
  394. X}         
  395. X
  396. void init_term()
  397. X{
  398. X   if (lpp() == 43)
  399. X      reset_43();   
  400. X   CUR_PAGE = cur_page();
  401. X   CHPL = chpl();
  402. X   LPP = lpp();
  403. X   wherexy(&C_X, &C_Y); 
  404. X}
  405. X
  406. private
  407. void near normfun();
  408. X
  409. void write_em(s)
  410. char *s;
  411. X{
  412. X  while (*s)
  413. X        normfun(*s++);
  414. X}          
  415. X
  416. void write_emif(s)
  417. char *s;
  418. X{
  419. X  if (s)
  420. X     write_em(s);
  421. X}
  422. X
  423. void write_emc(s, n)
  424. char *s;
  425. int n;
  426. X{
  427. X   while (n--)
  428. X         normfun(*s++);
  429. X}           
  430. X
  431. private
  432. void near normfun(c)
  433. char c;
  434. X{
  435. X      switch (c) {
  436. X        case 10: line_feed(); break;
  437. X        case 13: carriage_return(); break;
  438. X        case  8: back_space(); break;
  439. X        case  7: dobell(0); break;
  440. X        case  0: break;
  441. X        default: wrch(c);
  442. X      }  
  443. X}
  444. X
  445. X#endif    /* IBMPC */
  446. X
  447. X
  448. extern int    BufSize;
  449. X
  450. int    AbortCnt,
  451. X    tabstop = 8;
  452. X
  453. X#if !(defined(IBMPC) || defined(MAC))    
  454. int    (*TTins_line)(),
  455. X    (*TTdel_line)();
  456. X#endif /* (defined(IBMPC) || defined(MAC)) */
  457. X
  458. struct scrimage
  459. X    *DesiredScreen = 0,
  460. X    *PhysScreen = 0;
  461. X
  462. struct screenline    *Screen = 0,    /* the screen (a bunch of screenline) */
  463. X            *Savelines = 0,    /* another bunch (LI of them) */
  464. X            *Curline = 0;    /* current line */
  465. char    *cursor,            /* offset into current Line */
  466. X    *cursend;
  467. X
  468. int    CapCol,
  469. X    CapLine,
  470. X
  471. X    i_line,
  472. X    i_col;
  473. X
  474. void
  475. make_scr()
  476. X{
  477. X    register int    i;
  478. X    register struct screenline    *ns;
  479. X    register char    *nsp;
  480. X
  481. X#ifdef RESHAPING
  482. X    /* In case we are RESHAPING the window! */
  483. X    if (DesiredScreen)
  484. X        free((char *) DesiredScreen);
  485. X    if (PhysScreen)
  486. X        free((char *) PhysScreen);
  487. X    if (Savelines)
  488. X        free((char *) Savelines);
  489. X    if (Screen) {
  490. X        free(Screen->s_line);    /* free all the screen data */
  491. X        free((char *) Screen);
  492. X    }
  493. X#endif /* RESHAPING */
  494. X
  495. X    DesiredScreen = (struct scrimage *) malloc((unsigned) LI * sizeof (struct scrimage));
  496. X    PhysScreen = (struct scrimage *) malloc((unsigned) LI * sizeof (struct scrimage));
  497. X
  498. X    Savelines = (struct screenline *)
  499. X            malloc((unsigned) LI * sizeof(struct screenline));
  500. X    ns = Screen = (struct screenline *)
  501. X            malloc((unsigned) LI * sizeof(struct screenline));
  502. X
  503. X    nsp = (char *) malloc((unsigned)CO * LI);
  504. X    if (nsp == 0) {
  505. X        printf("\n\rCannot malloc screen!\n");
  506. X        finish(1);
  507. X    }
  508. X
  509. X    for (i = 0; i < LI; i++) {
  510. X        ns->s_line = nsp;
  511. X        nsp += CO;
  512. X        ns->s_length = nsp - 1;        /* End of Line */
  513. X        ns += 1;
  514. X    }
  515. X    cl_scr(0);
  516. X}
  517. X
  518. void
  519. clrline(cp1, cp2)
  520. register char    *cp1,
  521. X        *cp2;
  522. X{
  523. X    while (cp1 <= cp2)
  524. X        *cp1++ = ' ';
  525. X}
  526. X
  527. X#if !(defined(IBMPC) || defined(MAC))
  528. X#define sputc(c)    ((*cursor != (char) (c)) ? dosputc(c) : (cursor++, i_col++))
  529. X#endif /* (defined(IBMPC) || defined(MAC)) */
  530. X
  531. X#ifdef IBMPC
  532. int force = 0;
  533. X#define sputc(c)    dosputc(c)
  534. X#endif /* IBMPC */
  535. X
  536. X#ifdef MAC
  537. X#define sputc(c)    bufputc(c)    /* line buffered for mac display */
  538. X#endif /* MAC */
  539. X
  540. X#define soutputc(c)    if (--n <= 0) break; else sputc(c)
  541. X
  542. void
  543. cl_eol()
  544. X{
  545. X    if (cursor > cursend)
  546. X        return;
  547. X
  548. X    if (cursor < Curline->s_length) {
  549. X#if !(defined(IBMPC) || defined(MAC))
  550. X        if (CE) {
  551. X#endif /* (defined(IBMPC) || defined(MAC)) */
  552. X            Placur(i_line, i_col);
  553. X#ifdef TERMCAP
  554. X            putpad(CE, 1);
  555. X#else 
  556. X        clr_eoln();
  557. X#endif /* TERMCAP */
  558. X            clrline(cursor, Curline->s_length);
  559. X#if !(defined(IBMPC) || defined(MAC))
  560. X        } else {
  561. X        /* Ugh.  The slow way for dumb terminals. */
  562. X            register char *savecp = cursor;
  563. X
  564. X            while (cursor <= Curline->s_length)
  565. X                sputc(' ');
  566. X            cursor = savecp;
  567. X        }
  568. X#endif /* (defined(IBMPC) || defined(MAC)) */
  569. X        Curline->s_length = cursor;
  570. X    }
  571. X}
  572. X
  573. void
  574. cl_scr(doit)
  575. X{
  576. X    register int    i;
  577. X    register struct screenline    *sp = Screen;
  578. X
  579. X    for (i = 0; i < LI; i++, sp++) {
  580. X        clrline(sp->s_line, sp->s_length);
  581. X        sp->s_length = sp->s_line;
  582. X        PhysScreen[i].s_id = 0;
  583. X    }
  584. X    if (doit) {
  585. X#ifdef TERMCAP
  586. X        putpad(CL, LI);
  587. X#else 
  588. X        clr_page();
  589. X#endif /* TERMCAP */
  590. X        CapCol = CapLine = 0;
  591. X        UpdMesg = YES;
  592. X    }
  593. X}
  594. X
  595. X#ifdef ID_CHAR
  596. extern int    IN_INSmode;
  597. X#endif
  598. X
  599. X/* Output one character (if necessary) at the current position */
  600. X
  601. X#ifndef MAC
  602. int        /* only for lints sake */
  603. dosputc(c)
  604. register char    c;
  605. X{
  606. X#ifndef IBMPC
  607. X    if (*cursor != c) {
  608. X#ifdef ID_CHAR
  609. X        if (IN_INSmode)
  610. X            INSmode(0);
  611. X#endif
  612. X#else /* IBMPC */
  613. X    if ((force) || (*cursor != c)) {
  614. X#endif /* IBMPC */
  615. X        if (i_line != CapLine || i_col != CapCol)
  616. X            Placur(i_line, i_col);
  617. X#ifndef IBMPC
  618. X        if (UL && (c & CHARMASK) == '_' && (*cursor & CHARMASK) != ' ')
  619. X            putstr(" \b");        /* Erase so '_' looks right. */
  620. X#endif /* IBMPC */
  621. X        *cursor++ = c;
  622. X#ifndef IBMPC
  623. X        putchar(c & CHARMASK);
  624. X#else /* IBMPC */
  625. X        normfun(c);
  626. X#endif /* IBMPC */
  627. X        AbortCnt -= 1;
  628. X        CapCol += 1;
  629. X        i_col += 1;
  630. X    } else {
  631. X        cursor += 1;
  632. X        i_col += 1;
  633. X    }
  634. X}
  635. X#else /* MAC */
  636. X
  637. X/* Character output to bit-mapped screen is very expensive. It makes
  638. X   much more sense to write the entire line at once. So, we print all
  639. X   the characters, whether already there or not, once the line is
  640. X   complete.  */
  641. X   
  642. X#define BUFFLUSH (char) 0
  643. X#define BUFSTART (char) 1
  644. X    
  645. bufputc(c)
  646. register char c;
  647. X{
  648. X    static char buf[256];
  649. X    static int len = 0;
  650. X    
  651. X    if(c == BUFSTART) {
  652. X/*        if (i_line != CapLine || i_col != CapCol)*/
  653. X            NPlacur(i_line, i_col);
  654. X        len = 0;
  655. X        return;
  656. X    }
  657. X    if(c == BUFFLUSH) {
  658. X        buf[0] = (unsigned char) len;
  659. X        writechr(buf);
  660. X        len = 0;
  661. X    }
  662. X    else {
  663. X        if(len > 255) return;
  664. X        *cursor++ = c;
  665. X        if(c == '0') buf[++len] = 0xAF;    /* slashed zero */
  666. X         else buf[++len] = c;
  667. X        CapCol++;
  668. X        i_col++;
  669. X    }
  670. X    return;
  671. X}
  672. X#endif /* MAC */
  673. X
  674. X/* Write `line' at the current position of `cursor'.  Stop when we
  675. X   reach the end of the screen.  Aborts if there is a character
  676. X   waiting.  */
  677. X
  678. X#ifdef MAC        /* This was getting too complicated with ifdefs ... */
  679. int
  680. swrite(line, inversep, abortable)
  681. register char    *line;
  682. register int    abortable;
  683. X{
  684. X    register int    c;
  685. X    int    col = i_col,
  686. X        aborted = 0;
  687. X    register int    n = cursend - cursor;
  688. X
  689. X    if (n <= 0)
  690. X        return 1;
  691. X    sputc(BUFSTART);    /* Okay, because no interruption possible */
  692. X
  693. X    while (c = *line++) {
  694. X        if (c == '\t') {
  695. X            int    nchars;
  696. X
  697. X            nchars = (tabstop - (col % tabstop));
  698. X            col += nchars;
  699. X
  700. X            while (nchars--)
  701. X                soutputc(' ');
  702. X            if (n <= 0)
  703. X                break;
  704. X        } else if (isctrl(c)) {
  705. X            soutputc('^');
  706. X            c = ((c == '\177') ? '?' : c + '@');
  707. X            soutputc(c);
  708. X            col += 2;
  709. X        } else {
  710. X            soutputc(c);
  711. X            col += 1;
  712. X        }
  713. X    }
  714. X    if (n <= 0) {
  715. X        if ((*line == '\0') && (c != '\t') && !isctrl(c))
  716. X            sputc(c);
  717. X            sputc('!');
  718. X    }
  719. X    if (cursor > Curline->s_length)
  720. X        Curline->s_length = cursor;
  721. X    sputc(BUFFLUSH);
  722. X    return !aborted;
  723. X}
  724. X#else /* MAC */
  725. X
  726. int
  727. swrite(line, inversep, abortable)
  728. register char    *line;
  729. register int    abortable;
  730. X{
  731. X    register int    c;
  732. X    int    col = i_col,
  733. X        aborted = 0;
  734. X    register int    n = cursend - cursor;
  735. X#ifndef IBMPC
  736. X    int    or_byte = inversep ? 0200 : 0,
  737. X        thebyte;
  738. X#else 
  739. X    int    thebyte;
  740. X#endif /* IBMPC */
  741. X
  742. X#ifdef IBMPC
  743. X        force = inversep? 1: 0;  /* to force a redraw of the modeline */
  744. X#endif /* IBMPC */
  745. X
  746. X    if (n <= 0)
  747. X        return 1;
  748. X    while (c = *line++) {
  749. X#if !(defined(IBMPC) || defined(MAC))    /* don't check after every character */
  750. X        if (abortable && AbortCnt < 0) {
  751. X            AbortCnt = BufSize;
  752. X            if (InputPending = charp()) {
  753. X                aborted = 1;
  754. X                break;
  755. X            }
  756. X        }
  757. X#endif /* (defined(IBMPC) || defined(MAC)) */
  758. X        if (c == '\t') {
  759. X            int    nchars;
  760. X
  761. X            nchars = (tabstop - (col % tabstop));
  762. X            col += nchars;
  763. X
  764. X#ifndef IBMPC
  765. X            thebyte = (' ' | or_byte);
  766. X#endif /* IBMPC */
  767. X            while (nchars--)
  768. X#ifndef IBMPC
  769. X                soutputc(thebyte);
  770. X#else /* IBMPC */
  771. X                soutputc(' ');
  772. X#endif /* IBMPC */
  773. X            if (n <= 0)
  774. X                break;
  775. X        } else if (isctrl(c)) {
  776. X#ifndef IBMPC
  777. X            thebyte = ('^' | or_byte);
  778. X            soutputc(thebyte);
  779. X            thebyte = (((c == '\177') ? '?' : c + '@') | or_byte);
  780. X            soutputc(thebyte);
  781. X#else /* IBMPC */
  782. X            soutputc('^');
  783. X            c = ((c == '\177') ? '?' : c + '@');
  784. X            soutputc(c);
  785. X#endif /* IBMPC */
  786. X            col += 2;
  787. X        } else {
  788. X#ifndef IBMPC
  789. X            thebyte = (c | or_byte);
  790. X            soutputc(thebyte);
  791. X#else /* IBMPC */
  792. X             if (c == 255) c = 1;
  793. X            if (c == ' ' && inversep) c = 255;
  794. X            soutputc(c);
  795. X#endif /* IBMPC */
  796. X            col += 1;
  797. X        }
  798. X    }
  799. X    if (n <= 0) {
  800. X        if ((*line == '\0') && (c != '\t') && !isctrl(c))
  801. X#ifndef IBMPC
  802. X            sputc(c|or_byte);
  803. X#else /* IBMPC */
  804. X            sputc(c);
  805. X#endif /* IBMPC */
  806. X        else
  807. X#ifndef IBMPC
  808. X            sputc('!'|or_byte);
  809. X#else /* IBMPC */
  810. X            sputc('!');
  811. X#endif /* IBMPC */
  812. X    }
  813. X    if (cursor > Curline->s_length)
  814. X        Curline->s_length = cursor;
  815. X#ifdef IBMPC
  816. X    force = 0;
  817. X#endif
  818. X    return !aborted;
  819. X}
  820. X#endif /* MAC */
  821. X/* This is for writing a buffer line to the screen.  This is to
  822. X   minimize the amount of copying from one buffer to another buffer.
  823. X   This gets the info directly from the disk buffers. */
  824. X
  825. int
  826. BufSwrite(linenum)
  827. X{
  828. X    register int    n = cursend - cursor,
  829. X            col = 0,
  830. X            c = -1;
  831. X    register char    *bp;
  832. X    int    StartCol = DesiredScreen[linenum].s_offset,
  833. X        visspace = DesiredScreen[linenum].s_window->w_flags & W_VISSPACE,
  834. X        aborted = 0;
  835. X
  836. X    bp = lcontents(DesiredScreen[linenum].s_lp);
  837. X    if (*bp) for (;;) {
  838. X        if (col >= StartCol) {
  839. X            DesiredScreen[linenum].s_offset = col;
  840. X            break;
  841. X        }
  842. X
  843. X        c = *bp++ & CHARMASK;
  844. X        if (c == '\0')
  845. X            break;
  846. X        if (c == '\t')
  847. X            col += (tabstop - (col % tabstop));
  848. X        else if (isctrl(c))
  849. X            col += 2;
  850. X        else
  851. X            col += 1;
  852. X    }
  853. X#ifdef MAC
  854. X    sputc(BUFSTART);    /* Okay because we can't be interrupted */
  855. X#endif
  856. X
  857. X    if (c != '\0') while (c = *bp++) {
  858. X#if !(defined(IBMPC) || defined(MAC))        /* will never get true so why bother */
  859. X        if (AbortCnt < 0) {
  860. X            AbortCnt = BufSize;
  861. X            if (InputPending = charp()) {
  862. X                aborted = 1;
  863. X                break;
  864. X            }
  865. X        }
  866. X#endif /* (defined(IBMPC) || defined(MAC)) */
  867. X        if (c == '\t') {
  868. X            int    nchars = (tabstop - (col % tabstop));
  869. X
  870. X            col += nchars;
  871. X            if (visspace) {
  872. X                soutputc('>');
  873. X                nchars -= 1;
  874. X            }
  875. X            while (--nchars >= 0)
  876. X                soutputc(' ');
  877. X            if (n <= 0)
  878. X                break;
  879. X        } else if (isctrl(c)) {
  880. X            soutputc('^');
  881. X            soutputc((c == '\177') ? '?' : c + '@');
  882. X            col += 2;
  883. X        } else {
  884. X            if (c == ' ' && visspace)
  885. X                c = '_';
  886. X#ifdef IBMPC
  887. X            if (c == 255)
  888. X               c = 1;
  889. X#endif /* IBMPC */
  890. X            soutputc(c);
  891. X            col += 1;
  892. X        }
  893. X    }
  894. X    if (n <= 0) {
  895. X        if ((*bp == '\0') && (c != '\t') && !isctrl(c))
  896. X            sputc(c);
  897. X        else
  898. X            sputc('!');
  899. X    }
  900. X    if (cursor > Curline->s_length)
  901. X        Curline->s_length = cursor;
  902. X#ifdef MAC
  903. X    sputc(BUFFLUSH);
  904. X#endif
  905. X    return !aborted;        /* Didn't abort */
  906. X}
  907. X
  908. void
  909. i_set(nline, ncol)
  910. register int    nline,
  911. X        ncol;
  912. X{
  913. X    Curline = &Screen[nline];
  914. X    cursor = Curline->s_line + ncol;
  915. X    cursend = &Curline->s_line[CO - 1];
  916. X    i_line = nline;
  917. X    i_col = ncol;
  918. X}
  919. X
  920. X/* Insert `num' lines a top, but leave all the lines BELOW `bottom'
  921. X   alone (at least they won't look any different when we are done).
  922. X   This changes the screen array AND does the physical changes. */
  923. X
  924. void
  925. v_ins_line(num, top, bottom)
  926. X{
  927. X    register int    i;
  928. X
  929. X    /* Save the screen pointers. */
  930. X
  931. X    for(i = 0; i < num && top + i <= bottom; i++)
  932. X        Savelines[i] = Screen[bottom - i];
  933. X
  934. X    /* Num number of bottom lines will be lost.
  935. X       Copy everything down num number of times. */
  936. X
  937. X    for (i = bottom; i > top && i-num >= 0; i--)
  938. X        Screen[i] = Screen[i - num];
  939. X
  940. X    /* Restore the saved ones, making them blank. */
  941. X
  942. X    for (i = 0; i < num; i++) {
  943. X        Screen[top + i] = Savelines[i];
  944. X        clrline(Screen[top + i].s_line, Screen[top + i].s_length);
  945. X        Screen[top + i].s_length = Screen[top + i].s_line;
  946. X    }
  947. X
  948. X#if !(defined(IBMPC) || defined(MAC))
  949. X    (*TTins_line)(top, bottom, num);
  950. X#endif
  951. X
  952. X#ifdef MAC
  953. X    i_lines(top, bottom, num);
  954. X#endif 
  955. X
  956. X#ifdef IBMPC
  957. X    scr_win(-num, top, 0, bottom, CHPL-1);
  958. X#endif 
  959. X}
  960. X
  961. X/* Delete `num' lines starting at `top' leaving the lines below `bottom'
  962. X   alone.  This updates the internal image as well as the physical image.  */
  963. X
  964. void
  965. v_del_line(num, top, bottom)
  966. X{
  967. X    register int    i,
  968. X            bot;
  969. X
  970. X    bot = bottom;
  971. X
  972. X    /* Save the lost lines. */
  973. X
  974. X    for (i = 0; i < num && top + i <= bottom; i++)
  975. X        Savelines[i] = Screen[top + i];
  976. X
  977. X    /* Copy everything up num number of lines. */
  978. X
  979. X    for (i = top; num + i <= bottom; i++)
  980. X        Screen[i] = Screen[i + num];
  981. X
  982. X    /* Restore the lost ones, clearing them. */
  983. X
  984. X    for (i = 0; i < num; i++) {
  985. X        Screen[bottom - i] = Savelines[i];
  986. X        clrline(Screen[bot].s_line, Screen[bot].s_length);
  987. X        Screen[bot].s_length = Screen[bot].s_line;
  988. X        bot -= 1;
  989. X    }
  990. X
  991. X#if !(defined(IBMPC) || defined(MAC))
  992. X    (*TTdel_line)(top, bottom, num);
  993. X#endif
  994. X
  995. X#ifdef MAC
  996. X    d_lines(top, bottom, num);
  997. X#endif
  998. X
  999. X#ifdef IBMPC
  1000. X    scr_win(num, top, 0, bottom, CHPL-1);
  1001. X#endif 
  1002. X
  1003. X}
  1004. X
  1005. X#ifndef MAC    /* remainder of this file */
  1006. X#ifdef IBMPC
  1007. X
  1008. X/* No cursor optimization on an IBMPC, this simplifies things a lot.
  1009. X   Think about it: it would be silly!
  1010. X */
  1011. X
  1012. int    phystab = 8;
  1013. X
  1014. void
  1015. Placur(line, col)
  1016. X{
  1017. X    cur_mov(line, col);
  1018. X    CapCol = col;
  1019. X    CapLine = line;
  1020. X}
  1021. X
  1022. void
  1023. SO_on()
  1024. X{
  1025. X    if (Mdcolor)
  1026. X        setcolor(Mdcolor&0xf, Mdcolor>>4);
  1027. X    else
  1028. X        setcolor(Bgcolor, Fgcolor);
  1029. X}
  1030. X
  1031. void
  1032. SO_off()
  1033. X{
  1034. X   setcolor(Fgcolor, Bgcolor);
  1035. X}
  1036. X
  1037. extern int EGA;
  1038. X
  1039. void
  1040. X
  1041. UnsetTerm(foo)
  1042. char *foo;
  1043. X{
  1044. X  Placur(ILI, 0);
  1045. X  clr_eoln();
  1046. X  if (EGA)
  1047. X     reset_43();
  1048. X}
  1049. X
  1050. X
  1051. void
  1052. ResetTerm()
  1053. X{
  1054. X    if (EGA)
  1055. X       init_43();
  1056. X    else
  1057. X          init_term();
  1058. X       
  1059. X    do_sgtty();        /* this is so if you change baudrate or stuff
  1060. X                   like that, JOVE will notice. */
  1061. X    ttyset(ON);
  1062. X}
  1063. X
  1064. X#else /* IBMPC */ 
  1065. X
  1066. X/* The cursor optimization happens here.  You may decide that this
  1067. X   is going too far with cursor optimization, or perhaps it should
  1068. X   limit the amount of checking to when the output speed is slow.
  1069. X   What ever turns you on ...   */
  1070. X
  1071. private struct cursaddr {
  1072. X    int    cm_numchars,
  1073. X        (*cm_proc)();
  1074. X};
  1075. X
  1076. private char    *Cmstr;
  1077. private struct cursaddr    *HorMin,
  1078. X            *VertMin,
  1079. X            *DirectMin;
  1080. X
  1081. private void
  1082. X    GENi_lines(),
  1083. X    GENd_lines(),
  1084. X    ForMotion(),
  1085. X    ForTab(),
  1086. X    BackMotion(),
  1087. X    RetTab(),
  1088. X    DownMotion(),
  1089. X    UpMotion(),
  1090. X    GoDirect(),
  1091. X    HomeGo(),
  1092. X    BottomUp();
  1093. X    
  1094. X
  1095. private struct cursaddr    WarpHor[] = {
  1096. X    0,    ForMotion,
  1097. X    0,    ForTab,
  1098. X    0,    BackMotion,
  1099. X    0,    RetTab
  1100. X};
  1101. X
  1102. private struct cursaddr    WarpVert[] = {
  1103. X    0,    DownMotion,
  1104. X    0,    UpMotion
  1105. X};
  1106. X
  1107. private struct cursaddr    WarpDirect[] = {
  1108. X    0,    GoDirect,
  1109. X    0,    HomeGo,
  1110. X    0,    BottomUp
  1111. X};
  1112. X
  1113. X#undef    FORWARD
  1114. X#define    FORWARD        0    /* Move forward */
  1115. X#define FORTAB        1    /* Forward using tabs */
  1116. X#undef    BACKWARD
  1117. X#define    BACKWARD    2    /* Move backward */
  1118. X#define RETFORWARD    3    /* Beginning of line and then tabs */
  1119. X#define NUMHOR        4
  1120. X
  1121. X#define DOWN        0    /* Move down */
  1122. X#define UPMOVE        1    /* Move up */
  1123. X#define NUMVERT        2
  1124. X
  1125. X#define DIRECT        0    /* Using CM */
  1126. X#define HOME        1    /* HOME    */
  1127. X#define LOWER        2    /* Lower Line */
  1128. X#define NUMDIRECT    3
  1129. X
  1130. X#define    home()        Placur(0, 0)
  1131. X#define LowLine()    putpad(LL, 1), CapLine = ILI, CapCol = 0
  1132. X#define PrintHo()    putpad(HO, 1), CapLine = CapCol = 0
  1133. X
  1134. int    phystab = 8;
  1135. X
  1136. private void
  1137. GoDirect(line, col)
  1138. register int    line,
  1139. X        col;
  1140. X{
  1141. X    putpad(Cmstr, 1);
  1142. X    CapLine = line;
  1143. X    CapCol = col;
  1144. X}
  1145. X
  1146. private void
  1147. RetTab(col)
  1148. register int    col;
  1149. X{
  1150. X    putchar('\r');
  1151. X    CapCol = 0;
  1152. X    ForTab(col);
  1153. X}
  1154. X
  1155. private void
  1156. HomeGo(line, col)
  1157. X{
  1158. X    PrintHo();
  1159. X    DownMotion(line);
  1160. X    ForTab(col);
  1161. X}
  1162. X
  1163. private void
  1164. BottomUp(line, col)
  1165. register int    line,
  1166. X        col;
  1167. X{
  1168. X    LowLine();
  1169. X    UpMotion(line);
  1170. X    ForTab(col);
  1171. X}
  1172. X
  1173. X/* Tries to move forward using tabs (if possible).  It tabs to the
  1174. X   closest tabstop which means it may go past 'destcol' and backspace
  1175. X   to it. */
  1176. X
  1177. private void
  1178. ForTab(destcol)
  1179. int    destcol;
  1180. X{
  1181. X    register int    tabgoal,
  1182. X            ntabs,
  1183. X            tabstp = phystab;
  1184. X
  1185. X    if (TABS && (tabstp > 0)) {
  1186. X        tabgoal = destcol + (tabstp / 2);
  1187. X        tabgoal -= (tabgoal % tabstp);
  1188. X
  1189. X        /* Don't tab to last place or else it is likely to screw up. */
  1190. X        if (tabgoal >= CO)
  1191. X            tabgoal -= tabstp;
  1192. X
  1193. X        ntabs = (tabgoal / tabstp) - (CapCol / tabstp);
  1194. X        while (--ntabs >= 0)
  1195. X            putchar('\t');
  1196. X        CapCol = tabgoal;
  1197. X    }
  1198. X    if (CapCol > destcol)
  1199. X        BackMotion(destcol);
  1200. X    else if (CapCol < destcol)
  1201. X        ForMotion(destcol);
  1202. X}
  1203. X
  1204. private void
  1205. ForMotion(destcol)
  1206. register int    destcol;
  1207. X{
  1208. X    register int    nchars = destcol - CapCol;
  1209. X    register char    *cp = &Screen[CapLine].s_line[CapCol];
  1210. X
  1211. X    while (--nchars >= 0)
  1212. X        putchar(*cp++ & CHARMASK);
  1213. X    CapCol = destcol;
  1214. X}
  1215. X
  1216. private void
  1217. BackMotion(destcol)
  1218. register int    destcol;
  1219. X{
  1220. X    register int    nchars = CapCol - destcol;
  1221. X
  1222. X    if (BC)
  1223. X        while (--nchars >= 0)
  1224. X            putpad(BC, 1);
  1225. X    else
  1226. X        while (--nchars >= 0)
  1227. X            putchar('\b');
  1228. X    CapCol = destcol;
  1229. X}
  1230. X
  1231. private void
  1232. DownMotion(destline)
  1233. register int    destline;
  1234. X{
  1235. X    register int    nlines = destline - CapLine;
  1236. X
  1237. X    while (--nlines >= 0)
  1238. X        putpad(NL, 1);
  1239. X    CapLine = destline;
  1240. X}
  1241. X
  1242. private void
  1243. UpMotion(destline)
  1244. register int    destline;
  1245. X{
  1246. X    register int    nchars = CapLine - destline;
  1247. X
  1248. X    while (--nchars >= 0)
  1249. X        putpad(UP, 1);
  1250. X    CapLine = destline;
  1251. X}
  1252. X
  1253. X#ifdef ID_CHAR
  1254. static int    EIlen;
  1255. X#endif
  1256. extern int    IMlen;
  1257. X
  1258. void
  1259. InitCM()
  1260. X{
  1261. X    HOlen = HO ? strlen(HO) : 1000;
  1262. X    LLlen = LL ? strlen(LL) : 1000;
  1263. X    UPlen = UP ? strlen(UP) : 1000;
  1264. X#ifdef ID_CHAR
  1265. X    if (EI)
  1266. X        EIlen = strlen(EI);
  1267. X#endif
  1268. X}
  1269. X
  1270. void
  1271. Placur(line, col)
  1272. X{
  1273. X    int    dline,        /* Number of lines to move */
  1274. X        dcol;        /* Number of columns to move */
  1275. X    register int    best,
  1276. X            i;
  1277. X    register struct cursaddr    *cp;
  1278. X    int    xtracost = 0;    /* Misc addition to cost. */
  1279. X
  1280. X#define CursMin(which,addrs,max) \
  1281. X    for (best = 0, cp = &addrs[1], i = 1; i < max; i++, cp++) \
  1282. X        if (cp->cm_numchars < addrs[best].cm_numchars) \
  1283. X            best = i; \
  1284. X    which = &addrs[best];
  1285. X
  1286. X    if (line == CapLine && col == CapCol)
  1287. X        return;        /* We are already there. */
  1288. X
  1289. X    dline = line - CapLine;
  1290. X    dcol = col - CapCol;
  1291. X#ifdef ID_CHAR
  1292. X    if (IN_INSmode && MI)
  1293. X        xtracost = EIlen + IMlen;
  1294. X    /* If we're already in insert mode, it is likely that we will
  1295. X       want to be in insert mode again, after the insert. */
  1296. X#endif
  1297. X
  1298. X    /* Number of characters to move horizontally for each case.
  1299. X       1: Just move forward by typing the right character on the screen.
  1300. X       2: Print the correct number of back spaces.
  1301. X       3: Try tabbing to the correct place.
  1302. X       4: Try going to the beginning of the line, and then tab. */
  1303. X
  1304. X    if (dcol == 1 || dcol == 0) {        /* Most common case. */
  1305. X        HorMin = &WarpHor[FORWARD];
  1306. X        HorMin->cm_numchars = dcol + xtracost;
  1307. X    } else {
  1308. X        WarpHor[FORWARD].cm_numchars = dcol >= 0 ? dcol + xtracost : 1000;
  1309. X        WarpHor[BACKWARD].cm_numchars = dcol < 0 ? -(dcol + xtracost) : 1000;
  1310. X        WarpHor[FORTAB].cm_numchars = dcol >= 0 && TABS ?
  1311. X                ForNum(CapCol, col) + xtracost : 1000;
  1312. X        WarpHor[RETFORWARD].cm_numchars = (xtracost + 1 + (TABS ? ForNum(0, col) : col));
  1313. X
  1314. X        /* Which is the shortest of the bunch */
  1315. X
  1316. X        CursMin(HorMin, WarpHor, NUMHOR);
  1317. X    }
  1318. X
  1319. X    /* Moving vertically is more simple. */
  1320. X
  1321. X    WarpVert[DOWN].cm_numchars = dline >= 0 ? dline : 1000;
  1322. X    WarpVert[UPMOVE].cm_numchars = dline < 0 ? ((-dline) * UPlen) : 1000;
  1323. X
  1324. X    /* Which of these is simpler */
  1325. X    CursMin(VertMin, WarpVert, NUMVERT);
  1326. X
  1327. X    /* Homing first and lowering first are considered 
  1328. X       direct motions.
  1329. X       Homing first's total is the sum of the cost of homing
  1330. X       and the sum of tabbing (if possible) to the right. */
  1331. X    
  1332. X    if (VertMin->cm_numchars + HorMin->cm_numchars <= 3) {
  1333. X        DirectMin = &WarpDirect[DIRECT];    /* A dummy ... */
  1334. X        DirectMin->cm_numchars = 100;
  1335. X    } else {
  1336. X        WarpDirect[DIRECT].cm_numchars = CM ?
  1337. X                strlen(Cmstr = tgoto(CM, col, line)) : 1000;
  1338. X        WarpDirect[HOME].cm_numchars = HOlen + line +
  1339. X                WarpHor[RETFORWARD].cm_numchars;
  1340. X        WarpDirect[LOWER].cm_numchars = LLlen + ((ILI - line) * UPlen) +
  1341. X                WarpHor[RETFORWARD].cm_numchars;
  1342. X        CursMin(DirectMin, WarpDirect, NUMDIRECT);
  1343. X    }
  1344. X
  1345. X    if (HorMin->cm_numchars + VertMin->cm_numchars < DirectMin->cm_numchars) {
  1346. X        if (line != CapLine)
  1347. X            (*VertMin->cm_proc)(line);
  1348. X        if (col != CapCol) {
  1349. X#ifdef ID_CHAR
  1350. X            if (IN_INSmode)    /* We may use real characters ... */
  1351. X                INSmode(0);
  1352. X#endif
  1353. X            (*HorMin->cm_proc)(col);
  1354. X        }
  1355. X    } else {
  1356. X#ifdef ID_CHAR
  1357. X        if (IN_INSmode && !MI)
  1358. X            INSmode(0);
  1359. X#endif
  1360. X        (*DirectMin->cm_proc)(line, col);
  1361. X    }
  1362. X}
  1363. X
  1364. X#define abs(x)    ((x) >= 0 ? (x) : -(x))
  1365. X
  1366. int
  1367. ForNum(from, to)
  1368. register int    from;
  1369. X{
  1370. X    register int    tabgoal,
  1371. X            tabstp = phystab;
  1372. X    int        numchars = 0;
  1373. X
  1374. X    if (from >= to)
  1375. X        return from - to;
  1376. X    if (TABS && (tabstp > 0)) {
  1377. X        tabgoal = to + (tabstp / 2);
  1378. X        tabgoal -= (tabgoal % tabstp);
  1379. X        if (tabgoal >= CO)
  1380. X            tabgoal -= tabstp;
  1381. X        numchars = (tabgoal / tabstop) - (from / tabstp);
  1382. X        from = tabgoal;
  1383. X    }
  1384. X    return numchars + abs(from - to);
  1385. X}
  1386. X
  1387. X#ifdef WIRED_TERMS
  1388. X
  1389. void
  1390. BGi_lines(top, bottom, num)
  1391. X{
  1392. X    printf("\033[%d;%dr\033[%dL\033[r", top + 1, bottom + 1, num);
  1393. X    CapCol = CapLine = 0;
  1394. X}
  1395. X
  1396. void
  1397. SUNi_lines(top, bottom, num)
  1398. X{
  1399. X    Placur(bottom - num + 1, 0);
  1400. X    printf("\033[%dM", num);
  1401. X    Placur(top, 0);
  1402. X    printf("\033[%dL", num);
  1403. X}
  1404. X
  1405. void
  1406. C100i_lines(top, bottom, num)
  1407. X{
  1408. X    if (num <= 1) {
  1409. X        GENi_lines(top, bottom, num);
  1410. X        return;
  1411. X    }
  1412. X    printf("\033v%c%c%c%c", ' ', ' ', ' ' + bottom + 1, ' ' + CO);
  1413. X    CapLine = CapCol = 0;
  1414. X    Placur(top, 0);
  1415. X    while (num--)
  1416. X        putpad(AL, ILI - CapLine);
  1417. X    printf("\033v%c%c%c%c", ' ', ' ', ' ' + LI, ' ' + CO);
  1418. X    CapLine = CapCol = 0;
  1419. X}
  1420. X
  1421. X#endif /* WIRED_TERMS */
  1422. X
  1423. private void
  1424. GENi_lines(top, bottom, num)
  1425. X{
  1426. X    register int    i;
  1427. X
  1428. X    if (CS) {
  1429. X        putpad(tgoto(CS, bottom, top), 1);
  1430. X        CapCol = CapLine = 0;
  1431. X        Placur(top, 0);
  1432. X        for (i = 0; i < num; i++)
  1433. X            putpad(SR, bottom - top);
  1434. X        putpad(tgoto(CS, ILI, 0), 1);
  1435. X        CapCol = CapLine = 0;
  1436. X    } else {
  1437. X        Placur(bottom - num + 1, 0);
  1438. X        if (M_DL && (num > 1)) {
  1439. X            char    minibuf[16];
  1440. X
  1441. X            sprintf(minibuf, M_DL, num);
  1442. X            putpad(minibuf, ILI - CapLine);
  1443. X        } else {
  1444. X            for (i = 0; i < num; i++)
  1445. X                putpad(DL, ILI - CapLine);
  1446. X        }
  1447. X        Placur(top, 0);
  1448. X        if (M_AL && (num > 1)) {
  1449. X            char    minibuf[16];
  1450. X
  1451. X            sprintf(minibuf, M_AL, num);
  1452. X            putpad(minibuf, ILI - CapLine);
  1453. X        } else {
  1454. X            for (i = 0; i < num; i++)
  1455. X                putpad(AL, ILI - CapLine);
  1456. X        }
  1457. X    }
  1458. X}
  1459. X
  1460. X#ifdef WIRED_TERMS
  1461. X
  1462. void
  1463. BGd_lines(top, bottom, num)
  1464. X{
  1465. X    printf("\033[%d;%dr\033[%dM\033[r", top + 1, bottom + 1, num);
  1466. X    CapCol = CapLine = 0;
  1467. X}
  1468. X
  1469. void
  1470. SUNd_lines(top, bottom, num)
  1471. X{
  1472. X    Placur(top, 0);
  1473. X    printf("\033[%dM", num);
  1474. X    Placur(bottom + 1 - num, 0);
  1475. X    printf("\033[%dL", num);
  1476. X}
  1477. X
  1478. void
  1479. C100d_lines(top, bottom, num)
  1480. X{
  1481. X    if (num <= 1) {
  1482. X        GENd_lines(top, bottom, num);
  1483. X        return;
  1484. X    }
  1485. X    printf("\033v%c%c%c%c", ' ', ' ', ' ' + bottom + 1, ' ' + CO);
  1486. X    CapLine = CapCol = 0;
  1487. X    Placur(top, 0);
  1488. X    while (num--)
  1489. X        putpad(DL, ILI - CapLine);
  1490. X    printf("\033v%c%c%c%c", ' ', ' ', ' ' + LI, ' ' + CO);
  1491. X    CapLine = CapCol = 0;
  1492. X}
  1493. X
  1494. X#endif /* WIRED_TERMS */
  1495. X
  1496. private void
  1497. GENd_lines(top, bottom, num)
  1498. X{
  1499. X    register int    i;
  1500. X
  1501. X    if (CS) {
  1502. X        putpad(tgoto(CS, bottom, top), 1);
  1503. X        CapCol = CapLine = 0;
  1504. X        Placur(bottom, 0);
  1505. X        for (i = 0; i < num; i++)
  1506. X            putpad(SF, bottom - top);
  1507. X        putpad(tgoto(CS, ILI, 0), 1);
  1508. X        CapCol = CapLine = 0;
  1509. X    } else {
  1510. X        Placur(top, 0);
  1511. X        if (M_DL && (num > 1)) {
  1512. X            char    minibuf[16];
  1513. X
  1514. X            sprintf(minibuf, M_DL, num);
  1515. X            putpad(minibuf, ILI - top);
  1516. X        } else {
  1517. X            for (i = 0; i < num; i++)
  1518. X                putpad(DL, ILI - top);
  1519. X        }
  1520. X        Placur(bottom + 1 - num, 0);
  1521. X        if (M_AL && (num > 1)) {
  1522. X            char    minibuf[16];
  1523. X
  1524. X            sprintf(minibuf, M_AL, num);
  1525. X            putpad(minibuf, ILI - CapLine);
  1526. X        } else {
  1527. X            for (i = 0; i < num; i++)
  1528. X                putpad(AL, ILI - CapLine);
  1529. X        }
  1530. X    }
  1531. X}
  1532. X
  1533. struct ID_lookup {
  1534. X    char    *ID_name;
  1535. X    int    (*I_proc)();    /* proc to insert lines */
  1536. X    int    (*D_proc)();    /* proc to delete lines */
  1537. X} ID_trms[] = {
  1538. X    "generic",    GENi_lines,    GENd_lines,    /* This should stay here */
  1539. X#ifdef WIRED_TERMS
  1540. X    "sun",        SUNi_lines,    SUNd_lines,
  1541. X    "bg",        BGi_lines,    BGd_lines,
  1542. X    "c1",        C100i_lines,    C100d_lines,
  1543. X#endif /* WIRED_TERMS */
  1544. X    0,        0,        0
  1545. X};
  1546. X
  1547. void
  1548. IDline_setup(tname)
  1549. char    *tname;
  1550. X{
  1551. X    register struct ID_lookup    *idp;
  1552. X
  1553. X    for (idp = &ID_trms[1]; idp->ID_name; idp++)
  1554. X        if (strncmp(idp->ID_name, tname, strlen(idp->ID_name)) == 0)
  1555. X            break;
  1556. X    if (idp->ID_name == 0)
  1557. X        idp = &ID_trms[0];
  1558. X    TTins_line = idp->I_proc;
  1559. X    TTdel_line = idp->D_proc;
  1560. X}
  1561. X
  1562. X#endif /* IBMPC */
  1563. X#endif /* MAC */
  1564. END_OF_FILE
  1565. if test 28777 -ne `wc -c <'./screen.c'`; then
  1566.     echo shar: \"'./screen.c'\" unpacked with wrong size!
  1567. fi
  1568. # end of './screen.c'
  1569. fi
  1570. echo shar: End of archive 14 \(of 21\).
  1571. cp /dev/null ark14isdone
  1572. MISSING=""
  1573. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
  1574.     if test ! -f ark${I}isdone ; then
  1575.     MISSING="${MISSING} ${I}"
  1576.     fi
  1577. done
  1578. if test "${MISSING}" = "" ; then
  1579.     echo You have unpacked all 21 archives.
  1580.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1581. else
  1582.     echo You still need to unpack the following archives:
  1583.     echo "        " ${MISSING}
  1584. fi
  1585. ##  End of shell archive.
  1586. exit 0
  1587.